public class Code_34 {
    public int[] searchRange(int[] nums, int target) {
        int left=0;
        int right = nums.length-1;
        int mid;
        int start =-1;
        int end =-1;
        while (left<=right){
            mid = (left+right)/2;
            if (nums[mid] == target){
                return search(nums,mid);
            }else if (nums[mid] > target){
                right = mid-1;
            }else {
                left = mid +1;
            }
        }
        return new int[]{-1,-1};
    }

    public int[] search(int[] nums,int index){
        int left = index;
        while (left>=1 && nums[left-1] == nums[index]){
            left--;
        }
        int right = index;
        while (right<=nums.length-2 && nums[right+1] == nums[index]){
            right++;
        }
        return new int[]{left,right};
    }
}
